使用delphi在access DB中插入记录 | 您所在的位置:网站首页 › delphi insert access › 使用delphi在access DB中插入记录 |
我正在学习如何使用insert insert语句,并在access数据库中尝试插入单个记录。我要插入一个新记录的表有三个字段: StockID (AutoN)、Description (Text)、Cost (Number)。我看过以前的文章,但是发布的解决方案似乎超出了我的插入Into...which的基本级别,这是我感兴趣的。总之,这是我的密码..。 代码语言:javascript复制 adoQuery1.Active := true; adoQuery1.SQL.Clear; adoQuery1.SQL.Add('INSERT INTO Stock (StockID,Description,Cost) VALUES (4,Cheese,5)'); adoQuery1.open; adoQuery1.Close;它编译得很好,但是当按一个命令按钮来调用上面的命令时,我会得到以下消息: 'ADOQuery1:“缺少SQL属性”。 我做错什么了? 谢谢,阿贝利斯托。您的上一篇文章看起来很复杂,indeed...but,自从您的上一个解决方案启动并运行以来,我做了自己的小版本。很管用,所以我很高兴。现在,我将重点讨论如何从combobox中删除(用于字段选择)和用户价值。这是我的解决办法.;) 代码语言:javascript复制x:=strtoint(txtStockID.Text); y:=txtDescription.Text; z:=strtoCurr(txtCost.Text); adoQuery1.SQL.Clear; adoQuery1.SQL.Add('INSERT INTO tblStock (StockID,Description,Cost)'); adoQuery1.SQL.Add('VALUES (:StockID,:Description,:Cost)'); // ':StockID' denotes a parameter adoQuery1.Parameters.ParamByName('StockID').Value:= x; adoQuery1.Parameters.ParamByName('Description').Value:= y; adoQuery1.Parameters.ParamByName('Cost').Value:= z; adoQuery1.ExecSQL; adoQuery1.Close; |
CopyRight 2018-2019 实验室设备网 版权所有 |